package filters.pull;

import helper.PlanarImageWrapper;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.KernelJAI;

import org.apache.log4j.Logger;

import at.fhv.framework.filter.PassivePullFilter;
import at.fhv.framework.interfaces.Pull;

/**
 * The MedianFilter class.
 * 
 * @author Michael Sieber
 */
public class DilatePullFilter extends PassivePullFilter<PlanarImageWrapper, PlanarImageWrapper>
{
	private static Logger LOGGER = Logger.getLogger(DilatePullFilter.class);

	public DilatePullFilter(Pull<PlanarImageWrapper> source) 
	{
		super(source);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected boolean execute(PlanarImageWrapper entity, PlanarImageWrapper data) 
	{
		LOGGER.debug("dilate operation");
		
		float kernelMatrix[] = { 1, 1, 1, 
								 1, 1, 1, 
								 1, 1, 1 };
		
		KernelJAI kernel = new KernelJAI(3, 3, kernelMatrix);
		
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(data.getImage());
		pb.add(kernel);
		
		entity.setImage(JAI.create("dilate", pb));
		return true;
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected PlanarImageWrapper createEntity() 
	{
		return new PlanarImageWrapper();
	}
}
